import { DEFAULT_PRIMARY } from '@/config/config'
import piniaPersistConfig from '@/config/piniaPersist'
import { createPinia, defineStore } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { ThemeConfigProps } from './interface'
// import { createPinia } from 'pinia'
// const store = createPinia()
// export function setupStore(app: App<Element>): void {
//   app.use(store)
// }
// export { store }

// piniaPersist(持久化)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)

export default pinia

export const GlobalStore = defineStore('GlobalStore', {
  state: () => {
    return {
      // token
      token: '',
      // userInfo
      userInfo: '',
      // element组件大小
      assemblySize: 'default',
      // language
      language: '',
      // themeConfig
      themeConfig: {
        // 布局切换 ==>  纵向：vertical | 经典：classic | 横向：transverse | 分栏：columns
        layout: 'vertical',
        // 默认 primary 主题颜色
        primary: DEFAULT_PRIMARY,
        // 深色模式
        isDark: false,
        // 灰色模式
        isGrey: false,
        // 色弱模式
        isWeak: false,
        // 折叠菜单
        isCollapse: false,
        // 面包屑导航
        breadcrumb: true,
        // 面包屑导航图标
        breadcrumbIcon: true,
        // 标签页
        tabs: true,
        // 标签页图标
        tabsIcon: true,
        // 页脚
        footer: true,
        // 当前页面是否全屏
        maximize: false
      }
    }
  },
  getters: {},
  actions: {
    // setToken
    setToken(token: string) {
      this.token = token
    },
    // setUserInfo
    setUserInfo(userInfo: any) {
      this.userInfo = userInfo
    },
    // setAssemblySizeSize
    setAssemblySizeSize(assemblySize: string) {
      this.assemblySize = assemblySize
    },
    // updateLanguage
    updateLanguage(language: string) {
      this.language = language
    },
    // setThemeConfig
    setThemeConfig(themeConfig: ThemeConfigProps) {
      this.themeConfig = themeConfig
    }
  },
  persist: piniaPersistConfig('GlobalState')
})
